<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>递归</title>
	</head>
	<body>
		<script>
			// 递归就是函数体呢调用函数自身。执行过程相当于循环的执行函数.
			// 若未指定递归的停止条件.则递归会无限的执行下去.直到资源耗尽
			function setText(pText){
				pText += "3";
				console.log(pText);
				// 设定中断递归的条件
				if(pText.length > 500)
					return pText.length;
				return setText(pText);
			}
			
			// 计算阶乘的结果
			function fact(num){ 
				if (num<=1){ 
					return 1; 
				}else{ 
					return num * fact(num-1); 
				} 
			}
			
			result = fact(3);
			console.log('result=' + result);
			
			var result = setText("今天开始相加");
			console.log('result=' + result);
			function fib(count) {
				var count = parseInt(count);
				if (isNaN(count) || count < 0) {
					return 0;
				}
				function f(count) {
					if (count <= 1)
						return 1;
					return f(count - 1) + f(count - 2);   
				}
				return f(count);
			}
			result = fib(5);
			console.log("add2的计算结果为" + result);
		</script>
	</body>
</html>
